from typing import List, Optional
from pydantic import BaseModel, Field

from forward.utils.tool import to_lower_camel


'''
{
    "balance": "",
    "contact": {
        "credential": "410105196503018415",
        "credentialType": "1",
        "faceImageId": "",
        "name": "李修岭",
        "phone": "15136107396",
        "visitorPoint": ""
    },
    "createCells": [
        {
            "bookQuantity": 1,
            "productPriceId": "1781",
            "salePrice": 91,
            "settleMoney": 91,
            "startDate": "2025-01-17",
            "timeCode": "",
            "visitors": [
                {
                    "countryAlphaCode": "",
                    "countryName": "",
                    "credential": "410105196503018415",
                    "credentialType": "1",
                    "faceImageId": "",
                    "idCardType": "idcard",
                    "idIndex": "01737051364335",
                    "index": 0,
                    "name": "李修岭"
                }
            ]
        }
    ],
    "ecologyMemberId": "",
    "giftCouponQrCodeId": 66883,
    "memberTag": "",
    "partnerMerchantId": 2289,
    "paymentMode": 1,
    "performScreeningId": "",
    "priceGroupType": 3,
    "productCategory": 502,
    "scheduleCode": ""
}
'''


class VisitorSchema(BaseModel):
    country_alpha_code: Optional[str] = None
    country_name: Optional[str] = None
    credential: str
    credential_type: str
    face_image_id: Optional[str] = None
    id_card_type: str
    id_index: str
    index: int
    name: str


class CreateCellSchema(BaseModel):
    book_quantity: int
    product_price_id: int
    sale_price: float
    settle_money: float
    start_date: str
    time_code: Optional[str] = None
    visitors: List[VisitorSchema]


class ContactSchema(BaseModel):
    credential: str
    credential_type: str
    face_image_id: Optional[str] = None
    name: str
    phone: str
    visitor_point: Optional[str] = None


class ActivateInfoSchema(BaseModel):
    balance: Optional[str] = None
    contact: ContactSchema
    create_cells: List[CreateCellSchema]
    ecology_member_id: Optional[str] = None
    gift_coupon_qr_code_id: int
    member_tag: Optional[str] = None
    partner_merchant_id: int
    payment_mode: int
    perform_screening_id: Optional[str] = None
    price_group_type: int
    product_category: int
    schedule_code: Optional[str] = None
    token: str
    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,
    }


class CardInfoSchema(BaseModel):
    gift_coupon_qr_code_id: int
    merchant_id: int
    partner_merchant_id: int
    partner_code: str
    gift_coupon_order_id: int
    encrypt_id: str
    card_no: str
    allot_quantity: int
    activate_quantity: int
    coupon_batch_id: int
    coupon_name: str
    expired_time: str
    description: str
    background_picture_url: str
    product_spu_id: int
    product_category_id: int
    product_sku_id: int
    product_price_id: int
    product_price_list_id: int
    qr_code_status: int
    web_order_no: str
    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,
    }


class PlayerSchemaV1(BaseModel):
    name: str
    mobile: str
    id_number: str
    code: str
    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,
    }


class PlayerSchema(BaseModel):
    name: str
    mobile: str
    id_number: str
    card_info: CardInfoSchema
    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,
    }


class PriceDateDetail(BaseModel):
    price_date_plan_id: int
    begin_date: str
    end_date: str
    valid_weekdays: str
    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,
    }


class ProductInfoSchema(BaseModel):
    merchant_id: int
    product_price_id: int
    parent_product_price_id: int
    payment_mode_list: List[int]
    product_category_id: int
    product_scene_type_id: int
    product_spu_id: int
    product_spu_name: str
    poi_id: int
    poi_name: str
    poi_link_mobile: Optional[None] = None
    product_sku_id: int
    product_sku_name: str
    student_ticket_tag: int
    market_price_id: Optional[None] = None
    spu_picture_list: List[str]
    sku_picture_list: List[str]
    spu_description: str
    sku_description: str
    booking_remind: str
    market_price: float
    settle_price: float
    member_price: Optional[None] = None
    group_buy_price: Optional[None] = None
    market_share_price: Optional[None] = None
    market_promote_price: Optional[None] = None
    market_manage_price: Optional[None] = None
    lowest_price: float
    stock_plan_type: Optional[None] = None
    stock: Optional[None] = None
    sold_quantity: Optional[None] = None
    book_plan_id: int
    minimum_quantity: int
    maximum_quantity: int
    start_date: str
    end_date: str
    link_mobile: bool
    link_name: bool
    link_credential: bool
    link_credential_types: str
    real_name_book_rule_types: Optional[None] = None
    real_name_type: bool
    visitor_name: bool
    visitor_credential: bool
    visitor_credential_types: str
    collect_face_tag: bool
    collect_face_type: Optional[None] = None
    card_capture_tag: bool
    card_image_quantity: int
    office_letter_tag: bool
    office_letter_urls: Optional[None] = None
    refund_type: int
    allow_refund_tag: bool
    refund_before_use: bool
    allow_part_refund: bool
    allow_modify: bool
    advance_day: Optional[None] = None
    advance_time: Optional[None] = None
    ticket_active_type: int
    use_date_plan_id: int
    valid_date_name: str
    use_date_plan_type: int
    relative_unit: int
    relative_quantity: int
    line_days: Optional[None] = None
    start_canton_name: Optional[None] = None
    product_overview: Optional[None] = None
    line_schedule: Optional[None] = None
    book_description: Optional[None] = None
    line_schedule_jsons: Optional[None] = None
    coupon_valid_type: Optional[None] = None
    coupon_start_date: Optional[None] = None
    coupon_end_date: Optional[None] = None
    coupon_valid_hour: Optional[None] = None
    coupon_scope_type: Optional[None] = None
    site_channel_types: Optional[None] = None
    description: Optional[None] = None
    insurance_tag: bool
    electronic_fence_tag: bool
    member_price_tag: Optional[None] = None
    has_exist_perform_tag: bool
    product_hotel_config: Optional[None] = None
    perform_product_config: Optional[None] = None
    product_long_card_config: Optional[None] = None
    rent_product_info_config: Optional[None] = None
    product_sku_extra_config: Optional[None] = None
    specification_attribute: Optional[None] = None
    valid_tag: Optional[None] = None
    price_date_detail_list: List[PriceDateDetail]
    web_upload_config: Optional[None] = None
    model_config = {
        "alias_generator": to_lower_camel,
        "populate_by_name": True,
    }
